package com.bnyy.medicalHousekeeper.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.bnyy.common.Constant;
import com.bnyy.common.view.FormInfoItem;
import com.bnyy.medicalHousekeeper.DialogHelper;
import com.bnyy.medicalHousekeeper.R;
import com.bnyy.medicalHousekeeper.base.App;
import com.bnyy.medicalHousekeeper.base.BaseActivityImpl;
import com.bnyy.medicalHousekeeper.request.BaseObserverImpl;
import com.bnyy.medicalHousekeeper.request.RequestManager;

import java.util.HashMap;

import butterknife.BindView;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/12/13
 **/
public class SettingActivity extends BaseActivityImpl {
    @BindView(R.id.form_suggestion)
    FormInfoItem formSuggestion;
    @BindView(R.id.form_account_security)
    FormInfoItem formAccountSecurity;
    @BindView(R.id.form_agreement)
    FormInfoItem formAgreement;
    @BindView(R.id.form_privacy_rights)
    FormInfoItem formPrivacyRights;
    @BindView(R.id.form_permission_explain)
    FormInfoItem formPermissionExplain;
    @BindView(R.id.form_third_party_cooperation_list)
    FormInfoItem formThirdPartyCooperationList;
    @BindView(R.id.form_about)
    FormInfoItem formAbout;
    @BindView(R.id.tv_logout)
    TextView tvLogout;

    @Override
    public int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    public String getTitleStr() {
        return "设置";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        formAgreement.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewActivity.show(mContext, requestManager.getBaseUrl() + Constant.NetWork.URL_AGREEMENT);
            }
        });

        formPrivacyRights.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewActivity.show(mContext, requestManager.getBaseUrl() + Constant.NetWork.URL_PRIVACY_RIGHTS);
            }
        });

        formAbout.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseActivityImpl.show(mContext, AboutActivity.class);
            }
        });

        formSuggestion.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent questionIntent = new Intent(mContext, QuestionSuggestActivity.class);
//                startActivity(questionIntent);
            }
        });

        formAccountSecurity.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BaseActivityImpl.show(mContext, AccountSecurityActivity.class);
            }
        });

        formPermissionExplain.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseActivityImpl.show(mContext, PermissionExplainActivity.class);
            }
        });

        formThirdPartyCooperationList.setOnPressListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseActivityImpl.show(mContext, ThirdPartyCooperationListActivity.class);
            }
        });

        tvLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogHelper.showNormalDialog(mContext, "确定要退出登录吗？",
                        new DialogHelper.Callback() {

                            @Override
                            public void onRightClick(AlertDialog alertDialog) {
//                                MessageManager.logout();

//                                HashMap<String, String> params = new HashMap<>();
//                                params.put("alias", String.format("bnyy_user_%s", userInfoManager.getLoginUserId()));
//                                requestManager.request(requestManager.mJavaRetrofitService.deleteAlias(RequestManager.getJsonRequestBody(params)),
//                                        new BaseObserverImpl<Object>() {
//                                        });

                                requestManager.request(requestManager.mJavaRetrofitService.logout(),
                                        new BaseObserverImpl<Object>(mContext) {
                                            @Override
                                            public void onSuccess() {
                                                super.onSuccess();
                                                App.loginInvalid();
                                            }
                                        });
                            }
                        });
            }
        });
    }
}
